//
//  GCLayout.swift
//  GoCash
//
//  Created by jie on 2024/4/30.
//

import SwiftUI


let SCREEN_HEIGHT = UIScreen.main.bounds.height
let SCREEN_WIDHT = UIScreen.main.bounds.width


struct GCLayout {
   
    ///导航状态栏高度
    public static let statusBar_height = GCLayout().NAV_STATUSBAR_HEIGHT()
    ///底部导航菜单的指示条高度（屏幕底部安全距离）
    public static let bottomSafe_height = GCLayout().TABBAR_INDICATOR_HEIGHT()
    
    /// 导航栏内容高度
    public static let navBarContent_height = 44.0
    ///导航栏整体高度 状态栏高 + 导航栏内容高
    public static let navBar_height = (statusBar_height + navBarContent_height)
    ///底部导航菜单高度 内容高 + 底部指示条高度
    public static let tabBar_height = (49.0 + bottomSafe_height)
    
    //状态栏高度
    private func NAV_STATUSBAR_HEIGHT() -> CGFloat {
        if #available(iOS 13.0, *) {
            return GCWindow()?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0
        } else {
            return UIApplication.shared.statusBarFrame.height
        }
    }
    
    //底部指示条
    private func TABBAR_INDICATOR_HEIGHT() -> CGFloat {
        if #available(iOS 11.0, *) {
               return GCWindow()?.safeAreaInsets.bottom ?? 0
           } else {
               return 0
           }
    }
    
    //获取window
    private func GCWindow() -> UIWindow? {
        if #available(iOS 13.0, *) {
            let winScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
            return winScene?.windows.first
        } else {
            return UIApplication.shared.delegate?.window ?? UIApplication.shared.keyWindow
        }
    }
    
}
